package com.ruoyi.web.controller.memberCoupon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProductPassCardManagement;
import com.ruoyi.system.service.IProductPassCardManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品次卡管理 Controller
 *
 * @author ruoyi
 * @date 2025-05-22
 */
@Api(tags="商品次卡管理")
@RestController
@RequestMapping("/system/productPassCardManagement")
public class ProductPassCardManagementController extends BaseController
{
    @Autowired
    private IProductPassCardManagementService productPassCardManagementService;

    /**
     * 通过次卡名称和状态查询商品次卡管理列表
     */
    @ApiOperation("通过次卡名称和状态查询商品次卡管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String cardName,@RequestParam(required = false) String status)
    {
        startPage();
        List<ProductPassCardManagement> list = productPassCardManagementService.selectProductPassCardManagementList(cardName,status);
        return getDataTable(list);
    }

    /**
     * 导出商品次卡管理列表
     */
    @ApiOperation("导出商品次卡管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "商品次卡管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String cardName,@RequestParam(required = false) String status)
    {
        List<ProductPassCardManagement> list = productPassCardManagementService.selectProductPassCardManagementList(cardName,status);
        ExcelUtil<ProductPassCardManagement> util = new ExcelUtil<ProductPassCardManagement>(ProductPassCardManagement.class);
        util.exportExcel(response, list, "商品次卡管理数据");
    }

    /**
     * 通过id获取商品次卡管理详细信息
     */
    @ApiOperation("通过id获取商品次卡管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productPassCardManagementService.selectProductPassCardManagementById(id));
    }

    /**
     * 新增商品次卡管理
     */
    @ApiOperation("新增商品次卡管理")
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "商品次卡管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPassCardManagement productPassCardManagement)
    {
        return toAjax(productPassCardManagementService.insertProductPassCardManagement(productPassCardManagement));
    }

    /**
     * 修改商品次卡管理
     */
    @ApiOperation("修改商品次卡管理")
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "商品次卡管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPassCardManagement productPassCardManagement)
    {
        return toAjax(productPassCardManagementService.updateProductPassCardManagement(productPassCardManagement));
    }

    /**
     * 通过id批量删除商品次卡管理信息
     */
    @ApiOperation("通过id批量删除商品次卡管理信息")
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "商品次卡管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productPassCardManagementService.deleteProductPassCardManagementByIds(ids));
    }
}
